package com.serial.comm.modular.serialPort.model;

import com.serial.comm.core.constants.SystemConstants;
import lombok.Data;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.UUID;

/**
 * 与FODB系统通信专用对象
 */
@Data
public class FodbMsg implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 报文内容
     */
    private String message;
    /**
     * 报文唯一标识
     */
    private String sid;
    /**
     * 收报时间
     */
    private String recTime;
    /**
     * 发报时间
     */
    private String sendTime;
    /**
     * 发电地址
     */
    private String origin;
    /**
     * 收电地址
     */
    private String destination;
    /**
     * 优先级
     */
    private String priority;

    public FodbMsg() {
    }

    public FodbMsg(String message, String recTime, String sendTime, String origin, String destination, String priority) {
        this.message = message;
        this.recTime = recTime;
        this.sendTime = sendTime;
        this.origin = origin;
        this.destination = destination;
        this.priority = priority;
    }

    /**
     * 从Telegram 获取 FODB通信消息对象
     *
     * @param telegram
     * @return
     */
    public static FodbMsg convertFromTelegram(Telegram telegram) {
        SimpleDateFormat sdf = new SimpleDateFormat(SystemConstants.Pattern.DATE_FORMAT_1);
        FodbMsg fodbMsg = new FodbMsg(telegram.getText(),
                sdf.format(telegram.getRecDate()),
                telegram.getSendDate(),
                telegram.getOrigin(),
                telegram.getDestination(),
                telegram.getPriority());
        return fodbMsg;
    }


}
